const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')
const path = require('path')
// const AutoDllPlugin = require('autodll-webpack-plugin')
const AddAssetHtmlWebpackPlugin = require('add-asset-html-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

module.exports = defineConfig({
  publicPath: './',
  transpileDependencies: true,
  // configureWebpack: {
  // plugins: [

  // ]
  // },
  // devServer:{}
  configureWebpack: config => {
    // const dllPlugin = new AutoDllPlugin({
    //   inject: true, // will inject the DLL bundles to index.html
    //   filename: '[name].js',
    //   entry: {
    //     vue: ['vue'],
    //     'a': ['./src/a.js']
    //   }
    // })
    // config.plugins.push(dllPlugin)
    const arr = ['a']
    arr.forEach(name => {
      config.plugins.push(new webpack.DllReferencePlugin({
        manifest: path.resolve(__dirname, `./dll/${name}.manifest.json`)
      }))
      config.plugins.push(new AddAssetHtmlWebpackPlugin([
        {
          filepath: path.resolve(__dirname, `./dll/${name}.js`),
        }
      ]))
    })

    const bundle = new BundleAnalyzerPlugin()  // 使用默认配置
    config.plugins.push(bundle)


  },
  chainWebpack: config => {
    config.resolve.alias
      // key,value自行定义，比如.set('@assets', resolve('src/assets'))
      .set('@src', '/src')
  }
})
